#include "udebug.h"
#include "usocket.h"





const char* kwords[] = 
{
    "int",
    "fd ",
    "= ",
    "usocket_tcp_create_server(",
    "8080",
    "); "
};

#define LEN   1024
int main()
{
    int fd = usocket_tcp_connect_server("127.0.0.1", 8080);
    ulogdbg("fd=%d.\n", fd);

    int i;
    int n = sizeof(kwords)/sizeof(const char*);
    for(i=0; i<n; i++)
    {
    const char* buf = kwords[i];
    size_t sizec = strlen(buf);
    int nwrite = 0;
    while(nwrite != sizec)
    {
        int nw = write(fd, buf+nwrite, sizec-nwrite);
        if(nw <= 0) {
            printf("write error.(%d %s)\n", errno, strerror(errno));
            sleep(1);
            continue;
        }

        nwrite += nw;
        printf("====== wrote : %d .\n", nwrite);
    }

    char buf_echo[LEN];
    memset(buf_echo, 0, LEN);
    int n = read(fd, buf_echo, LEN-1);
    ulogdbg("n=%d\n", n);

    ulogdbg("\n---------------------------------------""%s\n"
            "-----------------------------------\n", buf);
    }

    close(fd);

    return 0;
}
